<template>
  <div class="all">
    <header>
      <div class="div" @click="back()">
        <img src="../../assets/返回.png" alt="">
        <span class="side">返回</span>
      </div>
      <div class="div">
        <span>新的朋友</span>
      </div>
      <div class="div"></div>
    </header>
    <div class="content">
      <van-empty
        style="width: 100%;height: 60%"
        v-show="requestList.length <= 0"
        class="custom-image"
        :image="require('../../assets/空两本书.png')"
        description="暂无好友申请记录"
      />
      <ul v-for="(item, index) in requestList" :key="index">
        <li class="li_left" @click="clickpeoInfo(item.USER_ID)">
          <img v-if="item.PHOTO === undefined || item.PHOTO === null || item.PHOTO === ''"
            src="../../assets/女患者@2x.png" alt="">
          <img v-else :src="item.PHOTO" alt="">
        </li>
        <li class="li_content">
          <p class="name">{{item.NICK_NAME}}</p>
          <p class="message">
            {{item.msg}}
          </p>
        </li>
        <li class="li_right">
          <button class="btn" @click="agree(item.id, item)">同意</button>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import $ from 'jquery'
import {Toast} from 'vant'
import videoHttp from '../../http/video.http'
export default {
  name: 'FriendRequest',
  data () {
    return {
      searchValue: '',
      userid: '',
      from_user_id: '',
      requestList: [],
      imgHttp: videoHttp.imgHttp
    }
  },
  mounted () {
    // 截取网址后的userid
    this.userid = this.$utils.getUrlKey('userid')
    this.from_user_id = this.$utils.getUrlKey('userid')
    $('.content').css('height', $(window).height() - $('.content').offset().top - 50 + 'px')
    // 查看好友申请列表
    this.getRequesr()
  },
  methods: {
    // 点击查看个人详情
    clickpeoInfo (id) {
      this.$router.push({path: '/detailsFriend', query: {userid: id}})
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    },
    // 获取好友申请数据
    getRequesr () {
      this.$http.findDaiTongGuoList({from_user_id: this.from_user_id})
        .then(res => {
          console.log(res)
          this.requestList = res.data.data
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 点击同意
    agree (id, item) {
      this.$http.updateCircleStatus({id: id})
        .then(res => {
          console.log(res)
          Toast('操作成功')
          if (sessionStorage.getItem('sys') === 'ANDROID') {
            window.WebViewJavascriptBridge.callHandler('friendApplyPass', item.USER_ID + ',' + item.NICK_NAME, function (responseData) {})
          }
          // friendApplyPass   通过好友申请时发送提示语方法名，参数：userid和userName，逗号拼接
          // 查看好友申请列表
          this.getRequesr()
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>

<style scoped>
  *{
    margin: 0;
    padding: 0;
  }
  .all{
    width: 100%;
    height: 100%;
    background: #FAF9FE;
  }
  header{
    width: 100%;
    height: 12vw;
    display: flex;
    font-size: 15px;
    font-weight: bold;
    font-family: "PingFang SC";
    background: #FFFFFF;
    border-bottom: 1px solid #E5E5E5;
  }
  header .div{
    width: 33%;
    display: flex;
    align-items: center;
  }
  header .div:nth-child(2){
    justify-content: center;
  }
  header .div:nth-child(3){
    flex-direction: row-reverse;
  }
  header .div:nth-child(3) .side{
    margin-right: 15px;
  }
  header .div img{
    width: 7px;
    height: 13px;
    margin: 0 5px 0 15px;
  }
  .side{
    color: #1da4f2;
  }
  .content{
    width: 100%;
    background: #FAF9FE;
    overflow: auto;
  }
  .content ul {
    width: 100%;
    /*height: 75px;*/
    display: flex;
    padding: 10px 0;
    background: #ffffff;
  }
  .content ul li{
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .li_left, .li_right{
    width: 22%;
  }
  .li_left img{
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .li_content{
    width: 55%;
    flex-direction: column;
  }
  .li_content p{
    width: 100%;
    font-family: PingFang SC;
    font-weight: 500;
    display: flex;
    align-items: center;
    padding-left: 10px;
  }
  .name{
    font-size: 15px;
    color: #333333;
    margin-bottom: 5px;
  }
  .message{
    width: 90%;
    text-align: left;
    font-size: 13px;
    color: rgba(153, 153, 153, 1);
  }
  .btn{
    width: 60px;
    height: 29px;
    background: #1DA4F2;
    border-radius: 14px;
    border: none;
    color: #FFFFFF;
  }
</style>
